package game

import (
	"errors"
	"log"
)

func (g *Game) buildTurn() { 
	g.turn=new(Turn)
	g.turn.turn=make([]int,len(g.Room.Group))
	for i:=range g.Gamers {
		g.turn.turn=append(g.turn.turn, int(i))
	}
	g.turn.turnpoint=0
}

func (t *Turn) GetNowturn() int {
	return t.turn[t.turnpoint]
}

func (t *Turn)GoNext() int {
	t.turnpoint++
	if t.turnpoint>=len(t.turn) {
		t.turnpoint=0
	}
	return t.turn[t.turnpoint]
}

func (t *Turn)SetTurn(uid int) error {
	for i:=range t.turn {
		if t.turn[i]==uid {
			t.turnpoint=i
			return nil
		}
	}
	log.Println("no such uid in turn")
	return errors.New("no such uid")
}